﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using CommonData;

namespace DataCentral.Forms
{
    public partial class ConfigAutoSendMailForm : CommonData.CommonChildForm
    {
        public ConfigAutoSendMailForm()
        {
            InitializeComponent();
        }

        private void LoadConfiguration()
        {
            txtHostMail.Text = Properties.Settings.Default.MAIL_Host;
            txtAccount.Text = Properties.Settings.Default.MAIL_Account;
            txtPassword.Text = CommonFunctions.DecodeFrom64(Properties.Settings.Default.MAIL_Password);
            txtPort.Text = Properties.Settings.Default.MAIL_Port.ToString();
            chkIsSSL.Checked = Properties.Settings.Default.MAIL_IsSSL;
            chkIsHTML.Checked = Properties.Settings.Default.MAIL_IsHTML;
            txtEmailTo.Text = Properties.Settings.Default.MAIL_MailTo;
            txtEmailCC.Text = Properties.Settings.Default.MAIL_MailCC;
            txtEmailBCC.Text = Properties.Settings.Default.MAIL_MailBCC;
            chkIsAutoMail.Checked = Properties.Settings.Default.MAIL_IsAutoSendMail;
            txtAutoTime.Time = Properties.Settings.Default.MAIL_TimeToSend;
        }

        private void SaveConfiguration()
        {
            Properties.Settings.Default.MAIL_Host = txtHostMail.Text;
            Properties.Settings.Default.MAIL_Account = txtAccount.Text;
            Properties.Settings.Default.MAIL_Password = CommonFunctions.EncodeTo64(txtPassword.Text);
            Properties.Settings.Default.MAIL_Port = Convert.ToInt16(txtPort.Text);
            Properties.Settings.Default.MAIL_IsSSL = chkIsSSL.Checked;
            Properties.Settings.Default.MAIL_IsHTML = chkIsHTML.Checked;
            Properties.Settings.Default.MAIL_MailTo = txtEmailTo.Text;
            Properties.Settings.Default.MAIL_MailCC = txtEmailCC.Text;
            Properties.Settings.Default.MAIL_MailBCC = txtEmailBCC.Text;
            Properties.Settings.Default.MAIL_IsAutoSendMail = chkIsAutoMail.Checked;
            Properties.Settings.Default.MAIL_TimeToSend =txtAutoTime.Time;

            Properties.Settings.Default.Save();
        }

        private void ConfigAutoSendMailForm_Load(object sender, EventArgs e)
        {
            LoadConfiguration();
        }

        private void txtAccount_EditValueChanged(object sender, EventArgs e)
        {
            txtEmailFrom.Text = txtAccount.Text;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveConfiguration();
            this.Close();
        }
    }
}